<template>
<div class='fx-icon_list'>
  <span
    class='fx-icon-style'
    v-for='(icon,index) in icons'
    :key='index'
    :class='[icon, icon + index]'
    @click='selectIcon(icon, index)'
  >
  </span>
</div>
</template>

<script>
export default {
  name: 'FxIconList',
  props:{
    icons: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data(){
    return {
      selected: ''
    }
  },
  methods:{
    selectIcon(icon, index){
      const current = document.querySelector(`.${icon + index}`)
      if(this.selected){
        document.querySelector(`.${this.selected}`).classList.remove('fx-icon-style__activated')
      }
      current.classList.add('fx-icon-style__activated')
      this.selected = icon + index
      this.$emit('getIcon', icon)
    }
  }
}
</script>

<style scoped>

.fx-icon_list {
  overflow: hidden;
  display: flex;
  padding-left: 20px;
  flex-flow: row wrap;
}

.fx-icon-style {
  display: block;
  position: relative;
  width: 36px;
  margin: 0 10px 20px 0;
  font-size: 30px;
  line-height: 36px;
  text-align: center;
  cursor: pointer;
  border: 1px solid #8c939d;
  transition: .4s;
}

.fx-icon-style:hover {
  color: #fff;
  background-color: rgb(74, 74, 72);
  transition: .3s;
}

.fx-icon-style__activated {
  color: #fff;
  background-color: rgb(74, 74, 72);
}
</style>
